home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / sys / amiga / programmer / 2112 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  1.9 KB

  1. Path: cs.uwa.edu.au!jasonb
  2. From: jasonb@cs.uwa.edu.au (Jason S Birch)
  3. Newsgroups: comp.sys.amiga.programmer
  4. Subject: Re: manipulating the stack in C
  5. Date: 27 Jan 96 04:50:23 GMT
  6. Organization: The University of Western Australia
  7. Message-ID: <jasonb.822718223@cs.uwa.edu.au>
  8. References: <4e8b20$lsq@newshost.lanl.gov> <Sh++x*aE0@mkmk.in-chemnitz.de>
  9. NNTP-Posting-Host: decadence.cs.uwa.oz.au
  10. X-Newsreader: NN version 6.5.0 #3 (NOV)
  11.  
  12. floh@mkmk.in-chemnitz.de (Andre Weissflog) writes:
  13. >I think it would be nicer if you give foo() the number of
  14. >args first, following the args:
  15.  
  16. >void foo(ULONG num_args,...);
  17.  
  18. >Since C pushes the last arg first, you will find num_args
  19.       ^^^
  20. >always at 4(a7), followed by the "real" arguments starting
  21. >at 8(a7):
  22.  
  23. I haven't got docs with me right now, but I think you'll find that
  24. this is compiler-dependent - ANSI C, AFAIR, doesn't define the order
  25. arguments will be put on the stack, or even, indeed, that they *will*
  26. be put on the stack (hence SAS/C's registerized parameters option is 
  27. perfectly legal). So, you'll have to keep that in mind, and also find
  28. out how your particular compiler does it, although all the ones I've
  29. checked do it the way you suggest (except SAS/C with registerized
  30. parameters, of course, or when a function is inlined).
  31.  
  32. Other than that, you're right - the normal way to do it is either put
  33. some sort of indication of the number as the first parameter (printf()
  34. looks at the format string to determine the number of arguments) or a
  35. special flag at the end (eg. TAG_DONE).
  36.  
  37. >Bye,
  38. >-Floh.
  39. >====//=== Andre Weissflog <floh@mkmk.in-chemnitz.de> =======
  40.  
  41. -- 
  42. Jason S Birch                        ,-_|\ email: jasonb@cs.uwa.edu.au
  43. Department of Computer Science      /     \ Tel (work): +61 9 380 1840
  44. The University of Western Australia *_.-._/ Fax (work): +61 9 380 1089
  45. Nedlands  W. Australia  6907             v  Tel (home): +61 9 386 8630
  46.